package cn.com.hbhgkj.web.struts2;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import cn.com.hbhgkj.bussiness.CopyrightAlterationService;
import cn.com.hbhgkj.common.ServiceException;
import cn.com.hbhgkj.pojo.CopyrightAlteration;

public class CopyrightAlterationAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String preSubmit() {
		try {
			if (copyrightAlteration != null
					&& copyrightAlteration.getId() != null) {
				copyrightAlteration = copyrightAlterationService
						.loadById(copyrightAlteration.getId());
			}

			this.success = true;
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
			return "review_failed";
		}
		return "preSubmit_success";
	}
	
	public String preReview() {
		try {
			if (copyrightAlteration != null
					&& copyrightAlteration.getId() != null) {
				copyrightAlteration = copyrightAlterationService
						.loadById(copyrightAlteration.getId());
			}

			this.success = true;
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
			return "review_failed";
		}
		return "preReview_success";
	}

	public String submit() {
		try {
			copyrightAlteration.setApplicant(this.getLoggedInUser());
			copyrightAlterationService.submit(copyrightAlteration);

			this.success = true;
			this.addActionMessage("保存成功，如需修改请在申请记录中进行修改!");
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
			return "review_failed";
		}
		return "review_success";
	}

	public String appliedRecords() {
		try {
			listCopyrightAlteration = copyrightAlterationService
					.findByApplicant(this.getLoggedInUser(), pagination);
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
		}
		return SUCCESS;
	}

	private CopyrightAlteration copyrightAlteration;

	private List<CopyrightAlteration> listCopyrightAlteration;

	public List<CopyrightAlteration> getListCopyrightAlteration() {
		return listCopyrightAlteration;
	}

	public void setListCopyrightAlteration(
			List<CopyrightAlteration> listCopyrightAlteration) {
		this.listCopyrightAlteration = listCopyrightAlteration;
	}

	public CopyrightAlteration getCopyrightAlteration() {
		return copyrightAlteration;
	}

	public void setCopyrightAlteration(CopyrightAlteration copyrightAlteration) {
		this.copyrightAlteration = copyrightAlteration;
	}

	private CopyrightAlterationService copyrightAlterationService;

	@JSON(serialize = false)
	public CopyrightAlterationService getCopyrightAlterationService() {
		return copyrightAlterationService;
	}

	public void setCopyrightAlterationService(
			CopyrightAlterationService copyrightAlterationService) {
		this.copyrightAlterationService = copyrightAlterationService;
	}

}
